//
//  FQDWebToolbar.m
//  FakeQDaily
//
//  Created by mewxiv on 9/12/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDWebToolbar.h"

#import "Masonry.h"

@interface FQDWebToolbar ()

// 分隔线
@property (nonatomic, strong) UIView *separatorLine;

@end

@implementation FQDWebToolbar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    _separatorLine = [[UIView alloc] init];
    _separatorLine.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
    [self addSubview:_separatorLine];
    
    UIImage *popBackImage = [UIImage imageNamed:@"comment_toolbar_back_normal"];
    _popBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_popBackButton setImage:popBackImage forState:UIControlStateNormal];
    [self addSubview:_popBackButton];
    
    UIImage *refreshImage = [UIImage imageNamed:@"toolbar_navigation_refresh_normal"];
    _refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_refreshButton setImage:refreshImage forState:UIControlStateNormal];
    [self addSubview:_refreshButton];
    
    UIImage *backImage = [UIImage imageNamed:@"toolbar_navigation_backward_normal"];
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_backButton setImage:backImage forState:UIControlStateNormal];
    [self addSubview:_backButton];
    
    UIImage *forwardImage = [UIImage imageNamed:@"toolbar_navigation_forward_normal"];
    _forwardButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_forwardButton setImage:forwardImage forState:UIControlStateNormal];
    [self addSubview:_forwardButton];
    
    UIImage *shareImage = [UIImage imageNamed:@"comment_toolbar_share_normal"];
    _shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_shareButton setImage:shareImage forState:UIControlStateNormal];
    [self addSubview:_shareButton];
    
}

- (void)prepareConstraints
{
    WeakSelf;
    
    [_separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.and.right.equalTo(weakSelf);
        make.height.equalTo(@0.5);
    }];
    
    [_popBackButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.equalTo(weakSelf);
        make.width.greaterThanOrEqualTo(@50);
        make.height.equalTo(@50);
    }];
    
    [_refreshButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf);
        make.right.equalTo(weakSelf.backButton.mas_left).offset(-15);
        make.width.lessThanOrEqualTo(@50);
        make.height.equalTo(@50);
    }];
    
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf);
        make.right.equalTo(weakSelf.forwardButton.mas_left).offset(-15);
        make.width.lessThanOrEqualTo(@50);
        make.height.equalTo(@50);
    }];
    
    [_forwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf);
        make.right.equalTo(weakSelf.shareButton.mas_left);
        make.width.lessThanOrEqualTo(@50);
        make.height.equalTo(@50);
    }];
    
    [_shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.right.equalTo(weakSelf);
        make.width.greaterThanOrEqualTo(@50);
        make.height.equalTo(@50);
    }];
    
}

@end
